package entity

// SettingsEntity settings
type SettingsEntity struct {
	ID    *string `gorm:"primaryKey;size:50"`
	Name  *string `gorm:"index"`
	Value *string
}

// TableName name
func (s *SettingsEntity) TableName() string {
	return "settings"
}

// FindByID find
func (s *SettingsEntity) FindByID(id string) (value string) {
	tmp := SettingsEntity{}
	GetDb().Select("value").Where("id = ?", id).Find(&tmp)
	return *tmp.Value
}

// Update update
func (s *SettingsEntity) Update(id string, value string) {
	GetDb().Model(SettingsEntity{}).Where("id = ?", id).Update("value", value)
}

// List list
func (s *SettingsEntity) List() (dst []SettingsEntity) {
	CheckDbRes(GetDb().Where("id <> ?", "db_init").Find(&dst))
	return
}
